<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物料编号" prop="GOODSID">
        <el-input
          v-model="queryParams.GOODSID"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="${comment}" prop="providerId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.providerId"-->
      <!--          placeholder="请输入${comment}"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
<!--      <el-form-item label="物料名称" prop="GOODSNAME">-->
<!--        <el-input-->
<!--          v-model="queryParams.GOODSNAME"-->
<!--          placeholder="请输入物料名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="库位编号" prop="locationId">
        <el-input
          v-model="queryParams.locationId"
          placeholder="请输入库位编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品型号" prop="BARCODE">
        <el-input
          v-model="queryParams.BARCODE"
          placeholder="请输入产品型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

<!--      <el-form-item label="状态" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="请选择状态"-->
<!--          clearable-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.rk_sts"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->

      <el-form-item label="上架时间" prop="ONDATEs">
        <el-date-picker
          clearable
          v-model="queryParams.ONDATEs"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期时间"
          end-placeholder="结束日期时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择上架时间范围">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="状态" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="请选择状态"-->
<!--          clearable-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.rk_sts"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>

    <el-table border
              ref="filterTable" v-loading="loading" :data="BAKList" :row-style="rowStyle"
              @selection-change="handleSelectionChange">
      <el-table-column
        fixed
        type="index"
        label="行号"
        width="60"
        align="center"
      />
      <el-table-column label="入库单号" sortable align="center" prop="lotId"/>
      <el-table-column label="产线" sortable align="center" prop="gropSc"/>
      <el-table-column label="任务编号" align="center" prop="plcID"/>
      <el-table-column label="托盘" sortable align="center" prop="ctl"/>
      <el-table-column label="库位" sortable align="center" prop="locationId"/>
      <el-table-column label="物料编号" sortable align="center" prop="goodsid"/>
      <el-table-column label="产品型号" sortable align="center" prop="barcode"/>
      <el-table-column label="备注" sortable align="center" prop="goodsname"/>
      <el-table-column label="数量" sortable align="center" prop="shelfNum"/>
      <el-table-column fixed="right" sortable label="入库时间" align="center" prop="ondate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ondate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList1"
    />

    <!-- 添加或修改入库查询对话框 -->

  </div>
</template>
<style>
.float-right-container {
  float: right; /* 容器向右浮动 */
  clear: both; /* 清除浮动，避免影响后续元素 */
}

.chart-container {
  display: flex;
  align-items: center; /* 使所有条形图和标签垂直居中 */
  gap: 10px; /* 条形图之间的间隔 */
}

.bar-container {
  display: flex;
  flex-direction: column;
  align-items: center; /* 使条形图和标签水平居中 */
}

.bar {
  width: 50px; /* 假设条形图的宽度为50px */
  margin-bottom: 5px; /* 条形图和标签之间的间隔 */
}

.label {
  font-size: 14px; /* 标签的字体大小 */
  color: #333; /* 标签的文字颜色 */
}
</style>
<script>
import {listBAK, getBAK, delBAK, addBAK, updateBAK,listFirst} from "@/api/system/OngoodsshelfBak";

export default {
  name: "BAK",
  dicts: ['rk_sts'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库查询表格数据
      BAKList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lotId: null,
        status: null,
        GOODSID: null,
        providerId: null,
        locationId: null,
        stoNum: null,
        ONDATEs: [],
        accNum: null,
        shelfNum: null,
        stockNum: null,
        ONDATE: null,
        ONSHELFUSERID: null,
        storageId: null,
        storageAreaId: null,
        upgoodsId: null,
        HASVOLUME: null,
        goodsTypeid: null,
        storageMode: null,
        productionDate: null,
        GOODSVOLUME: null,
        CTL: null,
        BARCODE: null,
        customerId: null,
        HIGH: null,
        ProDucLotId: null,
        UNIT: null,
        baozhiqi: null,
        PlcID: null,
        Whseloc: null,
        GOODSNAME: null,
        instand: null,
        wgh: null,
        TASKTYPE: null,
        goodsMeasureId: null,
        decid: null,
        packingNum: null,
        damageNum: null,
        warehousingId: null,
        VERSION: null,
        endtype: null,
        BarCodeTpe: null,
        lx: null,
        netWeigh: null,
        gltrp: null,
        SPECIFICATION: null,
        PARTDESC: null,
        BarCodef: null,
        GropSc: null,
        endInstand: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList1();
  },
  methods: {
    rowStyle({row, rowIndex}) {
      if (row.status === "0") {
        return {backgroundColor: '#faa5ac'}; // 返回被点击行的样式
      } else if (row.status === '1') {
        return {backgroundColor: '#ead6a3'};
      } else if (row.status === '2') {
        return {backgroundColor: '#a9bfed'};
      } else if (row.status === '10') {
        return {backgroundColor: '#a7dc83'};
      }
      return {}; // 返回其他行的默认样式
    },
    /** 首次查询入库查询列表 */
    getList1() {
      this.loading = true;
      listFirst(this.queryParams).then(response => {
        this.BAKList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询入库查询列表 */
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        lotId: null,
        GOODSID: null,
        providerId: null,
        locationId: null,
        stoNum: null,
        status: null,
        accNum: null,
        shelfNum: null,
        stockNum: null,
        ONDATE: null,
        ONSHELFUSERID: null,
        storageId: null,
        storageAreaId: null,
        upgoodsId: null,
        HASVOLUME: null,
        goodsTypeid: null,
        storageMode: null,
        productionDate: null,
        GOODSVOLUME: null,
        CTL: null,
        BARCODE: null,
        customerId: null,
        remark: null,
        HIGH: null,
        ProDucLotId: null,
        UNIT: null,
        baozhiqi: null,
        PlcID: null,
        Whseloc: null,
        GOODSNAME: null,
        instand: null,
        wgh: null,
        TASKTYPE: null,
        goodsMeasureId: null,
        decid: null,
        packingNum: null,
        damageNum: null,
        warehousingId: null,
        VERSION: null,
        endtype: null,
        BarCodeTpe: null,
        lx: null,
        netWeigh: null,
        gltrp: null,
        SPECIFICATION: null,
        PARTDESC: null,
        BarCodef: null,
        GropSc: null,
        endInstand: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList1();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.lotId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加入库查询";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const lotId = row.lotId || this.ids
      getBAK(lotId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改入库查询";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.lotId != null) {
            updateBAK(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList1();
            });
          } else {
            addBAK(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList1();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const lotIds = row.lotId || this.ids;
      this.$modal.confirm('是否确认删除入库查询编号为"' + lotIds + '"的数据项？').then(function () {
        return delBAK(lotIds);
      }).then(() => {
        this.getList1();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/BAK/export', {
        ...this.queryParams
      }, `BAK_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
